package com.andy.mvp.test.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.andy.mvp.R;
import com.andy.mvp.test.bean.Girl;

import java.util.List;

/**
 * @version V1.0
 * @描述:
 * @Company:
 * @auth: Created by AN .
 * @time: 2020/3/25 23:56
 * @des
 */
public class GirlAdapter extends BaseAdapter {
    private LayoutInflater inflater;
    private List<Girl> girls;

    public GirlAdapter(Context context, List<Girl> girs) {
        inflater = LayoutInflater.from(context);
        this.girls = girs;
    }

    @Override
    public int getCount() {
        return girls.size();
    }

    @Override
    public Object getItem(int position) {
        return girls.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
         ViewHolder holder=null;
        if(convertView == null){
            convertView=inflater.inflate(R.layout.item, null);
            holder = new ViewHolder();
            holder. iv_icon = (ImageView) convertView.findViewById(R.id.iv_icon);
            holder. tv_like = (TextView) convertView.findViewById(R.id.tv_like);
            holder. tv_style = (TextView) convertView.findViewById(R.id.tv_style);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }

        Girl g = girls.get(position);
        holder.iv_icon.setImageResource(g.icon);
        holder.tv_like.setText("喜欢程度:"+g.like);
        holder.tv_style.setText(g.style);

        return convertView;
    }
    private static class ViewHolder{
        ImageView iv_icon;
        TextView tv_like;
        TextView tv_style;
    }
}
